<?php
//  -----------------------------------------------------------------------  //
//                           Jobs for Xoops 2.0x                             //
//                  By John Mordo from the myAds 2.04 Module                 //
//                    All Original credits left below this                   //
//                                                                           //
//                                                                           //
//                                                                           //
//
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: Pascal Le Boustouller
// Author Website : pascal.e-xoops@perso-search.com
// Licence Type   : GPL
// ------------------------------------------------------------------------- //

	$mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
	
	require_once( XOOPS_ROOT_PATH."/modules/$mydirname/include/gtickets.php" ) ;


	/**
	 * funci�n para llenar la tabla de la p�gina index.php con las 10 �ltimas ofertas regsitradas
	 * var nb-afficahge: guarda el # de ofertas que se mostrar�n en la tabla 
	 *
	 */
function showNew()
{
	global $myts, $xoopsDB, $xoopsTpl, $xoopsModuleConfig, $mf, $xoopsUser, $mydirname;
	include_once(XOOPS_ROOT_PATH."/class/xoopstree.php");
	
	$nb_affichage = $xoopsModuleConfig['nb_affichage'];
	$mytree = new XoopsTree($xoopsDB->prefix("jobs_categories"),"cid","pid");
	
	$result=$xoopsDB->query("select lid, cid, title, programa, expire, type, company, price, typeprice, date, town, valid, photo, view FROM ".$xoopsDB->prefix("jobs_listing")." WHERE valid='Yes' ORDER BY date DESC LIMIT ".$xoopsModuleConfig['newclassifieds']."");
	if ($result){
// variables del template jobs_adlist.html	
		$xoopsTpl->assign('last_head', _JOBS_THE." ".$xoopsModuleConfig['newclassifieds']." "._JOBS_LASTADD);
		$xoopsTpl->assign('last_head_title', _JOBS_TITLE);
		$xoopsTpl->assign('last_head_company', _JOBS_COMPANY);
		$xoopsTpl->assign('last_head_date', _JOBS_DATE);
		$xoopsTpl->assign('last_head_local', _PROGRAMA);
		$xoopsTpl->assign('last_head_date2', _EXPIRA);
		$xoopsTpl->assign('salir',"<a href='salir.php'>"._SALIR."&nbsp;<img src=\"images/exit.png\" border=0 alt=\""._SALIR."\" /></a>");
		if ($xoopsUser) {
		if ($xoopsUser->isAdmin()) {
		$xoopsTpl->assign('salir',"<a href=\"". XOOPS_URL ."/user.php?op=logout\">"._SALIR."&nbsp;<img src=\"images/exit.png\" border=0 alt=\""._SALIR."\" /></a>");
		   }
		}
		$rank = 1;

//ciclo para llenar la tabla de index.php con las 10 ultimas ofertas		
		while(list($lid, $cid, $title, $programa, $expire, $type, $company, $price, $typeprice, $date, $town, $valid, $photo, $vu)=$xoopsDB->fetchRow($result)) {
			
			$resultcat=$xoopsDB->query("select title from ".$xoopsDB->prefix("jobs_categories")." WHERE cid=$cid");
			list($titlecat)=$xoopsDB->fetchRow($resultcat);
			
			$title = $myts->makeTboxData4Show($title);
			$expire = $myts->makeTboxData4Show($expire);
			$type = $myts->makeTboxData4Show($type);
			$company = $myts->makeTboxData4Show($company);
			$price = $myts->makeTboxData4Show($price);
			$town = $myts->makeTboxData4Show($town);
			
			$a_item = array();

			$useroffset = "";
	    	if($xoopsUser) {
				$timezone = $xoopsUser->timezone();
				if(isset($timezone)) {
					$useroffset = $xoopsUser->timezone();
				} else {
					$useroffset = $xoopsConfig['default_TZ'];
				}
			}

			$date = ($useroffset*3600) + $date;
			$date2 = $date + ($expire*86400);
			$date = formatTimestamp($date,"s");
			$date2 = formatTimestamp($date2,"s");

			$a_item['admin'] = "<a href='index.php?pa=viewlistings&amp;lid=$lid'><img src='images/home.png' border=0 alt=\""._JOBS_MODADMIN."\" /></a>";
// Si el usuario es administrador entonces muestra el icono de modificacion
			if ($xoopsUser) {
				if ($xoopsUser->isAdmin()) {
					$a_item['admin'] = "<a href='admin/index.php?op=ModJob&amp;lid=$lid'><img src='images/modif.gif' border=0 alt=\""._JOBS_MODADMIN."\" /></a>";
				}
			}

//llena la tabla con las 10 ultiams oferas con estos campos
			$a_item['title'] = "<a href='index.php?pa=viewlistings&amp;lid=$lid'>$title</a>";
//Si el usuario es administrador la p�gina de ofertas es "ofertas.php"			
			if ($xoopsUser) {
				if ($xoopsUser->isAdmin()) {
					$a_item['title'] = "<a href='ofertas.php?pa=viewlistings&amp;lid=$lid'>$title</a>";
				}
			}
			$a_item['company'] = $company;			
			$a_item['date'] = $date;		
			$a_item['local'] = $titlecat;
			$a_item['date2'] = $date2;

			$rank++;
			$xoopsTpl->append('items', $a_item);
		}
	}
}

/**
 * funci�n para llenar la tabla de la p�gina index2.php con las 10 �ltimas hojas de vida regsitradas
 * var nb-afficahge: guarda el # de ofertas que se mostrar�n en la tabla 
 * 
 */
function showResume()
{
	global $myts, $xoopsDB, $xoopsTpl, $xoopsModuleConfig, $mf, $xoopsUser, $mydirname;

	include_once(XOOPS_ROOT_PATH."/class/xoopstree.php");

	$newclassifieds = $xoopsModuleConfig['newclassifieds'];
	$nb_affichage = $xoopsModuleConfig['nb_affichage'];

	$mytree = new XoopsTree($xoopsDB->prefix("jobs_res_categories"),"cid","pid");
	
	$result=$xoopsDB->query("select lid, cid, name, title, exp, expire, private, programa, salary, typeprice, date, town, valid, view FROM ".$xoopsDB->prefix("jobs_resume")." WHERE valid='Yes' ORDER BY date DESC LIMIT $newclassifieds");
	if ($result){
// variables del template jobs_res_adlist.html		
		$xoopsTpl->assign('last_res_head', _JOBS_THE." ".$xoopsModuleConfig['newclassifieds']." "._JOBS_RES_LASTADD);
		$xoopsTpl->assign('last_res_head_experience', _PROGRAMA);
		$xoopsTpl->assign('last_res_head_title', _JOBS_TITLE7);
		$xoopsTpl->assign('last_res_head_date', _JOBS_DATE);
		$xoopsTpl->assign('last_res_head_local', _CARGOS);
		$xoopsTpl->assign('last_res_head_views', _EXP);
		
		$rank = 1;
		
//ciclo para llenar la tabla de index2.php con las 10 ultimas hojas de vida	
		while(list($lid, $cid, $name, $title, $exp, $expire, $private, $programa, $salary, $typeprice, $date, $town, $valid, $vu)=$xoopsDB->fetchRow($result)) {
			
			$resultcat=$xoopsDB->query("select title from ".$xoopsDB->prefix("jobs_res_categories")." WHERE cid=$cid");
			list($titlecat)=$xoopsDB->fetchRow($resultcat);
	
			$name = $myts->makeTboxData4Show($name);
			$title = $myts->makeTboxData4Show($title);
			$exp = $myts->makeTboxData4Show($exp);
			$private = $myts->makeTboxData4Show($private);
			$salary = $myts->makeTboxData4Show($salary);
			$typeprice = $myts->makeTboxData4Show($typeprice);
			$date = $myts->makeTboxData4Show($date);
			$town = $myts->makeTboxData4Show($town);

			$a_item = array();

			$useroffset = "";
	    	if($xoopsUser) {
				$timezone = $xoopsUser->timezone();
				if(isset($timezone)) {
					$useroffset = $xoopsUser->timezone();
				} else {
					$useroffset = $xoopsConfig['default_TZ'];
				}
			}

			$date = ($useroffset*3600) + $date;
			$date = formatTimestamp($date,"s");

			if ($xoopsUser) {
				if ($xoopsUser->isAdmin()) {
					$a_item['admin'] = "<a href='admin/index.php?op=ModResume&amp;lid=$lid'><img src='images/modif.gif' border=0 alt=\""._JOBS_MODADMIN2."\" /></a>";
				}
			}

			$a_item['title'] = "<a href='index2.php?pa=viewResume&amp;lid=$lid'>$name</a>";
			$a_item['private'] = $private;
			$a_item['exp'] = $titlecat;
			$a_item['name'] = $name;
			$a_item['date'] = $date;
			$a_item['local'] = $title;
			
			$a_item['views'] = $exp;

			$rank++;
			$xoopsTpl->append('items', $a_item);
		}
	}
}


/**
 * funci�n para llenar la tabla de la p�gina index_empresas.php con ls �ltimas empresas regsitradas
 * var nb-afficahge: guarda el # de empresas que se mostrar�n en la tabla 
 *
 */
function showEmpresas()
{
	global $myts, $xoopsDB, $xoopsTpl, $xoopsModuleConfig, $mf, $xoopsUser, $mydirname;
	include_once(XOOPS_ROOT_PATH."/class/xoopstree.php");
	
	$nb_affichage = $xoopsModuleConfig['nb_affichage'];
	$mytree = new XoopsTree($xoopsDB->prefix("jobs_categories"),"cid","pid");
	
	$result=$xoopsDB->query("select login, password, empresa, telefono, direccion, ciudad, sector, actividad, representante, cargo, email, fechareg FROM ".$xoopsDB->prefix("jobs_empresas")." ORDER BY fechareg DESC LIMIT ".$xoopsModuleConfig['newclassifieds']."");
	if ($result){
// variables del template jobs_empresas.html	
		$xoopsTpl->assign('empr_registradas_head', _JOBS_THE." ".$xoopsModuleConfig['newclassifieds']." "._JOBS_LASTADD2);
		$xoopsTpl->assign('empresa_head', _JOBS_COMPANY);
		$xoopsTpl->assign('nit_head', _NIT2);
		$xoopsTpl->assign('ciudad_head', _CIUDAD2);
		$xoopsTpl->assign('rep_head', _REP);
		$xoopsTpl->assign('fecha_head', _FECHA);
		
		$rank = 1;

//ciclo para llenar la tabla de index_empresas.php con las 10 ultimas empresas			
		while(list($login, $password, $empresa, $telefono, $direccion, $ciudad, $sector, $actividad, $representante, $cargo, $email, $fechareg)=$xoopsDB->fetchRow($result)) {
	        $empresa = $myts->makeTboxData4Save($empresa);
	        $telefono = $myts->makeTboxData4Save($telefono);
	        $direccion = $myts->makeTboxData4Save($direccion);
	        $ciudad = $myts->makeTboxData4Save($ciudad);
	        $sector = $myts->makeTboxData4Save($sector);
	        $actividad = $myts->makeTboxData4Save($actividad);
	        $representante = $myts->makeTboxData4Save($representante);
	        $cargo = $myts->makeTboxData4Save($cargo);
	        $email = $myts->makeTboxData4Save($email);
			
			$a_item = array();

			$useroffset = "";
	    	if($xoopsUser) {
				$timezone = $xoopsUser->timezone();
				if(isset($timezone)) {
					$useroffset = $xoopsUser->timezone();
				} else {
					$useroffset = $xoopsConfig['default_TZ'];
				}
			}

			$fechareg = ($useroffset*3600) + $fechareg;
			$fechareg = formatTimestamp($fechareg,"s");


			
			$a_item['admin'] = "<a href='index_empresas.php?pa=viewEmpresa&amp;login_empresa=$login'><img src='images/send.png' border=0 alt=\""._VER_EMPRESA."\" /></a>";
				
			$a_item['empresa'] = "<a href='index_empresas.php?pa=viewEmpresa&amp;login_empresa=$login'>$empresa</a>";
			$a_item['nit'] = $login;
			$a_item['ciudad'] = $ciudad;
			$a_item['rep'] = $representante;
			$a_item['fecha'] = $fechareg;

			$rank++;
			$xoopsTpl->append('items', $a_item);
		}
	}
}


/**
 * funci�n para llenar la tabla de la p�gina index_reportes.php con los �ltimos reportes de vinculaci�n
 * var nb-afficahge: guarda el # de reportes que se mostrar�n en la tabla 
 *
 */
function showReporte()
{
	global $myts, $xoopsDB, $xoopsTpl, $xoopsModuleConfig, $mf, $xoopsUser, $mydirname;
	include_once(XOOPS_ROOT_PATH."/class/xoopstree.php");
	
	$nb_affichage = $xoopsModuleConfig['nb_affichage'];
	$mytree = new XoopsTree($xoopsDB->prefix("jobs_categories"),"cid","pid");
	
	$result=$xoopsDB->query("select idreporte, idegresado, cargoegresado, observaciones, repempresa, idempresa, fechavinc FROM ".$xoopsDB->prefix("jobs_vinculados")." ORDER BY fechavinc DESC LIMIT ".$xoopsModuleConfig['newclassifieds']."");
	if ($result){
// variables del template jobs_view_reportes.html	
		$xoopsTpl->assign('reporte_head', _LOS." ".$xoopsModuleConfig['newclassifieds']." "._ULTIMOS);
		$xoopsTpl->assign('programa_egr_head',_PROGRAMA);
		$xoopsTpl->assign('egresado_head', _JOBS_TITLE7);
		$xoopsTpl->assign('obs_egr_head', _OBSERV2);
		$xoopsTpl->assign('cargo_egr_head', _CARGO_ASIGN);
		$xoopsTpl->assign('responsable_head', _VINCULADO_POR);
		$xoopsTpl->assign('fechavinc_head', _FECHAVINC);

		$rank = 1;
		
		while(list($idreporte, $idegresado, $cargoegresado, $observaciones, $repempresa, $idempresa, $fechavinc)=$xoopsDB->fetchRow($result)) {
			$idegresado = $myts->makeTboxData4Save($idegresado);
	        $cargoegresado = $myts->makeTboxData4Save($cargoegresado);
	        $observaciones = $myts->makeTboxData4Save($observaciones);
	        $repempresa = $myts->makeTboxData4Save($repempresa);
	        			
			$a_item = array();
			
		  $resultegresado = $xoopsDB->query("select lid, cid, name FROM ".$xoopsDB->prefix("jobs_resume")." WHERE numid='{$idegresado}'");
          list($lid, $cid, $nomegresado) = $xoopsDB->fetchRow($resultegresado);

          $resultcat=$xoopsDB->query("select title from ".$xoopsDB->prefix("jobs_res_categories")." WHERE cid=$cid");
		  list($programa)=$xoopsDB->fetchRow($resultcat);
		  
          $resultempresa = $xoopsDB->query("select empresa FROM ".$xoopsDB->prefix("jobs_empresas")." WHERE login='{$idempresa}'");
          list($nomempresa) = $xoopsDB->fetchRow($resultempresa);
		  

			$useroffset = "";
	    	if($xoopsUser) {
				$timezone = $xoopsUser->timezone();
				if(isset($timezone)) {
					$useroffset = $xoopsUser->timezone();
				} else {
					$useroffset = $xoopsConfig['default_TZ'];
				}
			}

			$fechavinc = ($useroffset*3600) + $fechavinc;
			$fechavinc = formatTimestamp($fechavinc,"s");
			
	
                           
			$a_item['egresado'] = "<a href='index2.php?pa=viewResume&amp;lid=$lid'>$nomegresado</a>";
			$a_item['programa_egr'] = $programa;        
			$a_item['cargo_egr'] = $cargoegresado;							
			$a_item['observaciones'] = $observaciones;
			$a_item['responsable'] = $repempresa;
			$a_item['empresa_egr'] = "<a href='index_empresas.php?pa=viewEmpresa&amp;login_empresa=$idempresa'>$nomempresa</a>";
			$a_item['fechavinc'] = $fechavinc;

			$rank++;
			$xoopsTpl->append('items', $a_item);
		}
	}
}


/**
 * funci�n para llenar las tablas de ofertas por programas 
 *
 * @param int $debut: # del primer objeto en la p�gina actual
 * @param int $cid: # de identificaci�n del programa
 * @param int $nb_affichage: # de ofertas que se mostrar�n por p�gina
 * @param int $nbe: # total de ofertas que registra ese programa
 */
function showViewListings($debut, $cid, $nb_affichage, $nbe)
{
    global $xoopsDB, $xoopsConfig, $xoopsTpl, $xoopsModuleConfig, $xoopsUser, $myts, $mydirname;
    
	$nb_affichage = $xoopsModuleConfig['nb_affichage'];
        
	// Add 'typeprice' by Tom
    //$result3=$xoopsDB->query("select lid, cid, title, type, company, price, date, town, valid, photo, view from ".$xoopsDB->prefix("jobs_listing")." where  valid='yes' AND cid=$cid order by date DESC  LIMIT $debut,$nb_affichage");
    $result3=$xoopsDB->query("select lid, cid, title, expire, type, company, price, typeprice, date, town, valid, photo, view from ".$xoopsDB->prefix("jobs_listing")." where  valid='Yes' AND cid=$cid order by date DESC  LIMIT $debut,$nb_affichage");

	$xoopsTpl->assign('data_rows', $nbe);
    if ($nbe =="0") {
		$xoopsTpl->assign('no_data', _JOBS_NOANNINCAT);
    } else {
		$xoopsTpl->assign('last_head', _JOBS_THE." ".$xoopsModuleConfig['newclassifieds']." "._JOBS_LASTADD);
		$xoopsTpl->assign('last_head_title', _JOBS_TITLE);
		$xoopsTpl->assign('last_head_company', _JOBS_COMPANY);
		$xoopsTpl->assign('last_head_price', _JOBS_PRICE);
		$xoopsTpl->assign('last_head_date', _JOBS_DATE);
		$xoopsTpl->assign('last_head_local', _JOBS_LOCAL2);
		$xoopsTpl->assign('last_head_date2', _EXPIRA);

		$rank = 1;
		
		while(list($lid, $cid, $title, $expire, $type, $company, $price, $typeprice, $date, $town, $valid, $photo, $vu)=$xoopsDB->fetchRow($result3)) {
			$a_item = array();
			$title = $myts->makeTboxData4Show($title);
			$expire = $myts->makeTboxData4Show($expire);
			$type = $myts->makeTboxData4Show($type);
			$company = $myts->makeTboxData4Show($company);
			$price = $myts->makeTboxData4Show($price);
			$town = $myts->makeTboxData4Show($town);
			$useroffset = "";

		    if($xoopsUser) {
				$timezone = $xoopsUser->timezone();
				if(isset($timezone)) {
					$useroffset = $xoopsUser->timezone();
				} else {
					$useroffset = $xoopsConfig['default_TZ'];
				}
			}

			$date = ($useroffset*3600) + $date;
			$date2 = $date + ($expire*86400);
			$date = formatTimestamp($date,"s");
			$date2 = formatTimestamp($date2,"s");

			if ($xoopsUser) {
				if ($xoopsUser->isAdmin()){
					$a_item['admin'] = "<a href='admin/index.php?op=ModJob&amp;lid=$lid'><img src='images/modif.gif' border=0 alt=\""._JOBS_MODADMIN."\" /></a>";
				}
			}

			$a_item['title'] = "<a href='index.php?pa=viewlistings&amp;lid=$lid'>$title</a>";
			if ($xoopsUser) {
				if ($xoopsUser->isAdmin()){
			$a_item['title'] = "<a href='ofertas.php?pa=viewlistings&amp;lid=$lid'>$title</a>";
				}
			}
			$a_item['company'] = $company;			
			$a_item['date'] = $date;
			$a_item['local'] = '';
			if ($town) {
				$a_item['local'] .= $town;
			}	
			$a_item['date2'] = $date2;
			
			$rank++;
			$xoopsTpl->append('items', $a_item);
		}
	}
}


/**
 * funci�n para mostrar las tablas de las hojas de vida por programas
 *
 * @param int $debut: # del primer objeto en la p�gina actual
 * @param int $cid: # de identificaci�n del programa
 * @param int $nb_affichage: # de hojas de vida que se mostrar�n por p�gina
 * @param int $nbe: # total de hojas de vida para ese programa
 */
function showViewResume($debut, $cid, $nb_affichage, $nbe)
{
    global $xoopsDB, $xoopsConfig, $xoopsTpl, $xoopsModuleConfig, $xoopsUser, $myts, $mydirname;
	
      $nb_affichage = $xoopsModuleConfig['nb_affichage'];
        
	// Add 'typeprice' by Tom
    //$result3=$xoopsDB->query("select lid, cid, title, type, company, price, date, town, valid, photo, view from ".$xoopsDB->prefix("jobs_resume")." where  valid='yes' AND cid=$cid order by date DESC  LIMIT $debut,$nb_affichage");
    $result3=$xoopsDB->query("select lid, cid, name, title, exp, expire, private, salary, typeprice, date, town, valid, view from ".$xoopsDB->prefix("jobs_resume")." where  valid='yes' AND cid=$cid order by date DESC  LIMIT $debut,$nb_affichage");

	$xoopsTpl->assign('data_rows', $nbe);
    if ($nbe =="0") {
		$xoopsTpl->assign('no_data', _JOBS_NOANNINCAT);
    } else {
		$xoopsTpl->assign('last_res_head', _JOBS_THE." ".$xoopsModuleConfig['newclassifieds']." "._JOBS_LASTADD);
		$xoopsTpl->assign('last_res_head_nombre', _JOBS_TITLE7);
		$xoopsTpl->assign('last_res_head_cargo', _CARGOS);
		$xoopsTpl->assign('last_res_head_exp', _EXP);
		$xoopsTpl->assign('last_res_head_local', _EXP);
		$xoopsTpl->assign('last_res_head_date', _FECHA_ACT);	

		$rank = 1;
		// Add 'typeprice' by Tom
		//while(list($lid, $cid, $title, $type, $company, $price, $date, $town, $valid, $photo, $vu)=$xoopsDB->fetchRow($result3))
		while(list($lid, $cid, $name, $title, $exp, $expire, $private, $salary, $typeprice, $date, $town, $valid, $vu)=$xoopsDB->fetchRow($result3)) {
			$a_item = array();
			$name = $myts->makeTboxData4Show($name);
			$title = $myts->makeTboxData4Show($title);
			$exp = $myts->makeTboxData4Show($exp);
			$expire = $myts->makeTboxData4Show($expire);
			$private = $myts->makeTboxData4Show($private);
			$salary = $myts->makeTboxData4Show($salary);
			$town = $myts->makeTboxData4Show($town);
			$useroffset = "";

		    if($xoopsUser) {
				$timezone = $xoopsUser->timezone();
				if(isset($timezone)) {
					$useroffset = $xoopsUser->timezone();
				} else {
					$useroffset = $xoopsConfig['default_TZ'];
				}
			}

			$date = ($useroffset*3600) + $date;
			$date = formatTimestamp($date,"s");

			if ($xoopsUser) {
				if ($xoopsUser->isAdmin()){
					$a_item['admin'] = "<a href='admin/index.php?op=ModResume&amp;lid=$lid'><img src='images/modif.gif' border=0 alt=\""._JOBS_MODADMIN."\" /></a>";
				}
			}

			$a_item['nombre'] = "<a href='index2.php?pa=viewResume&amp;lid=$lid'>$name</a>";
			$a_item['cargo'] = $title;
			$a_item['exp'] = $exp;
			$a_item['date'] = $date;	
			$a_item['local'] = '';
			if ($town) {
				$a_item['local'] .= $town;
			}
			
			$rank++;
			$xoopsTpl->append('items', $a_item);
		}
	}
}


/**
 * funci�n para mostrar todas las empresas registradas, ordenadas alfabeticamente
 *
 * @param int $debut: # del primer objeto en la p�gina
 * @param int $nb_affichage: # total de empresas que se mostrar�n por p�gina (10)
 * @param int $nbe: # total de empresas regsitradas
 */
function Empresas($debut, $nb_affichage, $nbe)
{
    global $xoopsDB, $xoopsConfig, $xoopsTpl, $xoopsModuleConfig, $xoopsUser, $myts, $mydirname;
    
	$nb_affichage = $xoopsModuleConfig['nb_affichage'];
        
    $result9=$xoopsDB->query("select login, password, empresa, telefono, direccion, ciudad, sector, actividad, representante, cargo, email, fechareg FROM ".$xoopsDB->prefix("jobs_empresas")." order by empresa ASC  LIMIT $debut,$nb_affichage");

	$xoopsTpl->assign('data_rows', $nbe);
    if ($nbe =="0") {
		$xoopsTpl->assign('no_data', _JOBS_NOANNINCAT);
    } else {
		$xoopsTpl->assign('last_head', _JOBS_THE." ".$xoopsModuleConfig['newclassifieds']." "._JOBS_LASTADD);
		$xoopsTpl->assign('last_head_title', _JOBS_TITLE);
		$xoopsTpl->assign('empresa_head', _JOBS_COMPANY);
		$xoopsTpl->assign('nit_head', _NIT2);
		$xoopsTpl->assign('ciudad_head', _CIUDAD2);
		$xoopsTpl->assign('rep_head', _REP);
		$xoopsTpl->assign('fecha_head', _FECHA);
		
		$rank = 1;
		
		while(list($login, $password, $empresa, $telefono, $direccion, $ciudad, $sector, $actividad, $representante, $cargo, $email, $fechareg)=$xoopsDB->fetchRow($result9)) {
			$a_item = array();
			$empresa = $myts->makeTboxData4Save($empresa);
	        $telefono = $myts->makeTboxData4Save($telefono);
	        $direccion = $myts->makeTboxData4Save($direccion);
	        $ciudad = $myts->makeTboxData4Save($ciudad);
	        $sector = $myts->makeTboxData4Save($sector);
	        $actividad = $myts->makeTboxData4Save($actividad);
	        $representante = $myts->makeTboxData4Save($representante);
	        $cargo = $myts->makeTboxData4Save($cargo);
	        $email = $myts->makeTboxData4Save($email);
			$useroffset = "";

		    if($xoopsUser) {
				$timezone = $xoopsUser->timezone();
				if(isset($timezone)) {
					$useroffset = $xoopsUser->timezone();
				} else {
					$useroffset = $xoopsConfig['default_TZ'];
				}
			}

			$fechareg = ($useroffset*3600) + $fechareg;		
			$fechareg = formatTimestamp($fechareg,"s");
			
			/* if ($xoopsUser) {
				if ($xoopsUser->isAdmin()){
					$a_item['admin'] = "<a href='admin/index.php?op=ModJob&amp;lid=$lid'><img src='images/modif.gif' border=0 alt=\""._JOBS_MODADMIN."\" /></a>";
				}
			} */
			$a_item['admin'] = "<a href='index_empresas.php?pa=viewEmpresa&amp;login_empresa=$login'><img src='images/send.png' border=0 alt=\""._VER_EMPRESA."\" /></a>";

			$a_item['empresa'] = "<a href='index_empresas.php?pa=viewEmpresa&amp;login_empresa=$login'>$empresa</a>";
			$a_item['nit'] = $login;
			$a_item['ciudad'] = $ciudad;
			$a_item['rep'] = $representante;
			$a_item['fecha'] = $fechareg;
			
						
			$rank++;
			$xoopsTpl->append('items', $a_item);
		}
	}
}

/**
 * funci�n para llenar las tablas de ofertas por empresa
 *
 * @param int $debut: # del primer objeto en la p�gina actual
 * @param int $login_empresa: # de identificaci�n de la empresa que env�a la oferta
 * @param int $nb_affichage: # de ofertas que se mostrar�n por p�gina
 * @param int $nbe: # total de ofertas que registra esa empresa
 */
function showEmpresasListings($debut, $login_empresa, $nb_affichage, $nbe)
{
    global $xoopsDB, $xoopsConfig, $xoopsTpl, $xoopsModuleConfig, $xoopsUser, $myts, $mydirname;
	
	$nb_affichage = $xoopsModuleConfig['nb_affichage'];
        
	// busca en la tabla de ofertas el id de la empresa	
	$rs = $xoopsDB->query("select submitter from ".$xoopsDB->prefix("jobs_listing")." where submitter=$login_empresa");
	list($submitter) = $xoopsDB->fetchRow($rs);
	//list($nom_empresa) = $xoopsDB->fetchRow($xoopsDB->query("select empresa from ".$xoopsDB->prefix("jobs_empresas")." WHERE login=$login_empresa"));
			
    $result3=$xoopsDB->query("select lid, cid, title, expire, type, company, price, typeprice, date, town, valid, photo, view from ".$xoopsDB->prefix("jobs_listing")." where submitter=$submitter order by date DESC  LIMIT $debut,$nb_affichage");

	$xoopsTpl->assign('data_rows', $nbe);
    if ($nbe =="0") {
		$xoopsTpl->assign('no_data', _JOBS_NOANNINCAT);
    } else {
		$xoopsTpl->assign('last_head', _JOBS_THE." ".$xoopsModuleConfig['newclassifieds']." "._JOBS_LASTADD);
		//$xoopsTpl->assign('last_head_title', );
		$xoopsTpl->assign('last_head_company', _JOBS_TITLE);
		$xoopsTpl->assign('last_head_date', _JOBS_DATE);
		$xoopsTpl->assign('last_head_local', _SAL2);
		$xoopsTpl->assign('last_head_date2', _EXPIRA);
		//$xoopsTpl->assign('availability', "<b>"._MIS_OFERTAS." <i>$nom_empresa<i></b>");

		$rank = 1;
		
		while(list($lid, $cid, $title, $expire, $type, $company, $price, $typeprice, $date, $town, $valid, $photo, $vu)=$xoopsDB->fetchRow($result3)) {
			$a_item = array();
			$title = $myts->makeTboxData4Show($title);
			$expire = $myts->makeTboxData4Show($expire);
			$type = $myts->makeTboxData4Show($type);
			$company = $myts->makeTboxData4Show($company);
			$price = $myts->makeTboxData4Show($price);
			$town = $myts->makeTboxData4Show($town);
			$useroffset = "";

		    if($xoopsUser) {
				$timezone = $xoopsUser->timezone();
				if(isset($timezone)) {
					$useroffset = $xoopsUser->timezone();
				} else {
					$useroffset = $xoopsConfig['default_TZ'];
				}
			}

			$date = ($useroffset*3600) + $date;
			$date2 = $date + ($expire*86400);
			$date = formatTimestamp($date,"s");
			$date2 = formatTimestamp($date2,"s");
			$price = number_format($price,0,",",".");

			if ($xoopsUser) {
				if ($xoopsUser->isAdmin()){
					$a_item['admin'] = "<a href='admin/index.php?op=ModJob&amp;lid=$lid'><img src='images/modif.gif' border=0 alt=\""._JOBS_MODADMIN."\" /></a>";
				}
			}

			//$a_item['title'] = "<a href='index.php?pa=viewlistings&amp;lid=$lid'>$title</a>";
			if ($valid == "No"){
			$a_item['title'] = "<img src=\"images/Expire.gif\" border=0 alt=\""._EXPIRED."\" />";
			}	
			$a_item['company'] = "<a href='ofertas.php?pa=viewlistings&amp;lid=$lid'>$title</a>";							
			$a_item['date'] = $date;			
			$a_item['local'] = "".$xoopsModuleConfig['monnaie']." $price";			
			$a_item['date2'] = $date2;
			
			$rank++;
			$xoopsTpl->append('items', $a_item);
		}
	}
}

/**
 * Funci�n para mostrar todos los reportes de vinculaci�n 
 *
 * @param int $debut: # del primer objeto en la p�gina actual
 * @param int $nb_affichage: # total de reportes que se mostrar�n por p�gina (10)
 * @param int $nbe: # total de reportes registrados
 */
function Reportes($debut, $nb_affichage, $nbe)
{
    global $xoopsDB, $xoopsConfig, $xoopsTpl, $xoopsModuleConfig, $xoopsUser, $myts, $mydirname;
    
	$nb_affichage = $xoopsModuleConfig['nb_affichage'];
        
    $result=$xoopsDB->query("select idreporte, idegresado, cargoegresado, observaciones, repempresa, idempresa, fechavinc FROM ".$xoopsDB->prefix("jobs_vinculados")." order by idreporte ASC  LIMIT $debut,$nb_affichage");

	$xoopsTpl->assign('data_rows', $nbe);
    if ($nbe =="0") {
		$xoopsTpl->assign('no_data', _JOBS_NOANNINCAT);
    } else {
		$xoopsTpl->assign('last_head', _JOBS_THE." ".$xoopsModuleConfig['newclassifieds']." "._JOBS_LASTADD);
		$xoopsTpl->assign('last_head_title', _JOBS_TITLE);
		$xoopsTpl->assign('egresado_head', _JOBS_TITLE7);
		$xoopsTpl->assign('programa_egr_head', _PROGRAMA);
		$xoopsTpl->assign('cargo_egr_head', _CARGO_ASIGN);
		$xoopsTpl->assign('responsable_head', _VINCULADO_POR);
		$xoopsTpl->assign('fechavinc_head', _FECHAVINC);
		$xoopsTpl->assign('obs_egr_head', _OBSERV2);
		
		$rank = 1;
		
		while(list($idreporte, $idegresado, $cargoegresado, $observaciones, $repempresa, $idempresa, $fechavinc)=$xoopsDB->fetchRow($result)) {
			$a_item = array();
			$idegresado = $myts->makeTboxData4Save($idegresado);
	        $cargoegresado = $myts->makeTboxData4Save($cargoegresado);
	        $observaciones = $myts->makeTboxData4Save($observaciones);
	        $repempresa = $myts->makeTboxData4Save($repempresa);
	      
		  $resultegresado = $xoopsDB->query("select lid, cid, name FROM ".$xoopsDB->prefix("jobs_resume")." WHERE numid='{$idegresado}'");
          list($lid, $cid, $nomegresado) = $xoopsDB->fetchRow($resultegresado);

          $resultcat=$xoopsDB->query("select title from ".$xoopsDB->prefix("jobs_res_categories")." WHERE cid=$cid");
		  list($programa)=$xoopsDB->fetchRow($resultcat);
		  
          $resultempresa = $xoopsDB->query("select empresa FROM ".$xoopsDB->prefix("jobs_empresas")." WHERE login='{$idempresa}'");
          list($nomempresa) = $xoopsDB->fetchRow($resultempresa);
		  
			$useroffset = "";

		    if($xoopsUser) {
				$timezone = $xoopsUser->timezone();
				if(isset($timezone)) {
					$useroffset = $xoopsUser->timezone();
				} else {
					$useroffset = $xoopsConfig['default_TZ'];
				}
			}

			$fechavinc = ($useroffset*3600) + $fechavinc;		
			$fechavinc = formatTimestamp($fechavinc,"s");
					
			$a_item['egresado'] = "<a href='index2.php?pa=viewResume&amp;lid=$lid'>$nomegresado</a>";
			$a_item['programa_egr'] = $programa;
			$a_item['cargo_egr'] = $cargoegresado;
			$a_item['responsable'] = $repempresa;
			$a_item['empresa_egr'] = "<a href='index_empresas.php?pa=viewEmpresa&amp;login_empresa=$idempresa'>$nomempresa</a>";
			$a_item['fechavinc'] = $fechavinc;
			$a_item['observaciones'] = $observaciones;
								
			$rank++;
			$xoopsTpl->append('items', $a_item);
		}
	}
}


/**
 * Funci�n para poner inactiva una oferta laboral despu�s de que pasa el tiempo establecido
 * compara la fecha actual con la fecha de expiraci�n
 *
 */
function ExpireJob()
{
//for xoops2//	
	//include("./include/config.php");
	global $xoopsDB, $xoopsConfig, $xoopsModuleConfig, $myts, $meta, $mydirname;

	$datenow = time();

	$result5 = $xoopsDB->query("select lid, title, expire, type, company, desctext, requirements, contactinfo, date, email, submitter, valid, photo, view FROM ".$xoopsDB->prefix("jobs_listing")." WHERE valid='Yes'");

	while(list($lids, $title, $expire, $type, $company, $desctext, $requirements, $contactinfo, $dateann, $email, $submitter, $valid, $photo, $lu) = $xoopsDB->fetchRow($result5)) {
		$title = $myts->makeTboxData4Show($title);
		$expire = $myts->makeTboxData4Show($expire);
		$type = $myts->makeTboxData4Show($type);
		$company = $myts->makeTboxData4Show($company);
		$desctext = $myts->makeTboxData4Show($desctext);
		$requirements = $myts->makeTboxData4Show($requirements);
		$contactinfo = $myts->makeTboxData4Show($contactinfo);
		$submitter = $myts->makeTboxData4Show($submitter);

		$supprdate = $dateann + ($expire*86400);

		if ($supprdate < $datenow) {
		//for xoops2//	$xoopsDB->query("delete from ".$xoopsDB->prefix("jobs_listing")." where lid='$lids'");
		
			//$xoopsDB->queryF("delete from ".$xoopsDB->prefix("jobs_listing")." where lid='$lids'");
			
			//Pone inactiva la oferta seleccionada
	        $xoopsDB->queryf("update ".$xoopsDB->prefix("jobs_listing")." set valid='No' where lid='$lids'");
			
			$destination = XOOPS_ROOT_PATH."/modules/$mydirname/logo_images";

			//	Specification for Japan: 
			//	$message = ""._JOBS_HELLO." $submitter,\n\n"._JOBS_STOP2."\n $type : $title\n $desctext\n"._JOBS_STOP3."\n\n"._JOBS_VU." $lu "._JOBS_VU2."\n\n"._JOBS_OTHER." ".XOOPS_URL."/modules/jobs\n\n"._JOBS_THANK."\n\n"._JOBS_TEAM." ".$meta['title']."\n".XOOPS_URL."";
			if ($email) {
				$message = "$submitter "._JOBS_HELLO." \n\n"._JOBS_STOP2."\n $type : $title\n $desctext\n"._JOBS_STOP3."\n\n"._JOBS_VU." $lu "._JOBS_VU2."\n\n"._JOBS_OTHER." ".XOOPS_URL."/modules/jobs\n\n"._JOBS_THANK."\n\n"._JOBS_TEAM." ".$meta['title']."\n".XOOPS_URL."";
				$subject = ""._JOBS_STOP."";
				$mail =& getMailer();
				$mail->useMail();
				$mail->setFromName($meta['title']);
				$mail->setFromEmail($xoopsConfig['adminmail']);
				$mail->setToEmails($email);
				$mail->setSubject($subject);
				$mail->setBody($message);
				$mail->send();
				echo $mail->getErrors();
			}
		}
	}
}


/**
 * Funci�n para borrar una hoja de vida despu�s de que se cumple el tiempo asignado por quien la cre�
 * Esta funci�n en su momento, no fue necesaria
 *
 */
/* 
function ExpireResume()
{
//for xoops2//	
	//include("./include/config.php");
	global $xoopsDB, $xoopsConfig, $xoopsModuleConfig, $myts, $meta, $mydirname;

	$datenow = time();

	$result5 = $xoopsDB->query("select lid, name, title, expire, private, date, email, submitter, resume, view FROM ".$xoopsDB->prefix("jobs_resume")." WHERE valid='Yes'");

	while(list($lids, $name, $title, $expire, $private, $dateann, $email, $submitter, $resume, $lu) = $xoopsDB->fetchRow($result5)) {

		$name = $myts->makeTboxData4Show($name);
		$title = $myts->makeTboxData4Show($title);
		$expire = $myts->makeTboxData4Show($expire);
		$private = $myts->makeTboxData4Show($private);
		$submitter = $myts->makeTboxData4Show($submitter);

		$supprdate = $dateann + ($expire*86400);

		if ($supprdate < $datenow) {
		//for xoops2//	$xoopsDB->query("delete from ".$xoopsDB->prefix("jobs_listing")." where lid='$lids'");
			$xoopsDB->queryF("delete from ".$xoopsDB->prefix("jobs_resume")." where lid='$lids'");

			$destination = XOOPS_ROOT_PATH."/modules/$mydirname/resumes";

			if($resume) {
				if (file_exists("$destination/$resume")) {
					unlink("$destination/$resume");
				}
			}

			//	Specification for Japan: 
			//	$message = ""._JOBS_HELLO." $submitter,\n\n"._JOBS_STOP2."\n $type : $title\n $desctext\n"._JOBS_STOP3."\n\n"._JOBS_VU." $lu "._JOBS_VU2."\n\n"._JOBS_OTHER." ".XOOPS_URL."/modules/jobs\n\n"._JOBS_THANK."\n\n"._JOBS_TEAM." ".$meta['title']."\n".XOOPS_URL."";
			if ($email) {
				$message = "$submitter "._JOBS_HELLO." \n\n"._JOBS_STOP2."\n $type : $title\n $desctext\n"._JOBS_STOP3."\n\n"._JOBS_VU." $lu "._JOBS_VU2."\n\n"._JOBS_OTHER." ".XOOPS_URL."/modules/jobs\n\n"._JOBS_THANK."\n\n"._JOBS_TEAM." ".$meta['title']."\n".XOOPS_URL."";
				$subject = ""._JOBS_STOP."";
				$mail =& getMailer();
				$mail->useMail();
				$mail->setFromName($meta['title']);
				$mail->setFromEmail($xoopsConfig['adminmail']);
				$mail->setToEmails($email);
				$mail->setSubject($subject);
				$mail->setBody($message);
				$mail->send();
				echo $mail->getErrors();
			}
		}
	}
}
*/

function copyright()
{
	global $xoopsTpl, $mydirname;
	include(XOOPS_ROOT_PATH."/modules/$mydirname/xoops_version.php");
	$cr_developed = "jobs ".$modversion['version']." "._JOBS_FOR." Xoops "._JOBS_CREATBY." <a href=\"http://www.searchsouthington.com/\" target=\"_blank\">John Mordo</a>";
	$cr_redesigned = "redesigned from myads 2.04";

	if (isset($GLOBALS['xoopsOption']['template_main'])) {
		$xoopsTpl->assign('cr_developed', $cr_developed);
		$xoopsTpl->assign('cr_redesigned', $cr_redesigned);
	}
}


function getTotalItems($sel_id, $status="")
{
     global $xoopsDB, $mytree, $mydirname;
     $pfx = $xoopsDB->prefix("jobs_listing");
     $count = 1;
     $arr = array();
     $status_q = '';

     if ($status) {
          if ($status == _YES){
               $status_q = " and valid='Yes'";
          } else {
               $status_q = " and valid='No'";
          }
     }

     $query = "select lid from $pfx where cid=".$sel_id."$status_q";
     $result = $xoopsDB->query($query);
     $count = $xoopsDB->getRowsNum($result);
     $arr = $mytree->getAllChildId($sel_id);
     $size = sizeof($arr);

     for($i=0;$i<$size;$i++) {
          $query2 = "select lid from $pfx where cid=".$arr[$i]."$status_q";
          $result2 = $xoopsDB->query($query2);
          $count += $xoopsDB->getRowsNum($result2);
     }

     return $count;
}


function getTotalResumes($sel_id, $status="")
{
     global $xoopsDB, $mytree, $mydirname;
     $pfx = $xoopsDB->prefix("jobs_resume");
     $count = 1;
     $arr = array();
     $status_q = '';

     if ($status) {
          if ($status == _YES){
               $status_q = " and valid='Yes'";
          } else {
               $status_q = " and valid='No'";
          }
     }

     $query = "select lid from $pfx where cid=".$sel_id."$status_q";
     $result = $xoopsDB->query($query);
     $count = $xoopsDB->getRowsNum($result);
     $arr = $mytree->getAllChildId($sel_id);
     $size = sizeof($arr);

     for($i=0;$i<$size;$i++) {
          $query2 = "select lid from $pfx where cid=".$arr[$i]."$status_q";
          $result2 = $xoopsDB->query($query2);
          $count += $xoopsDB->getRowsNum($result2);
     }

     return $count;
}


function ShowImg()
{
	global $mydirname;
	
	echo "<script type=\"text/javascript\">\n";
	echo "<!--\n\n";
	echo "function showimage() {\n";
	echo "if (!document.images)\n";
	echo "return\n";
	echo "document.images.avatar.src=\n";
	echo "'".XOOPS_URL."/modules/$mydirname/images/cat/' + document.imcat.img.options[document.imcat.img.selectedIndex].value\n";
	echo "}\n\n";
	echo "//-->\n";
	echo "</script>\n";
}

function JobTableExists($tablename)
	{
		global $xoopsDB;
		$result=$xoopsDB->queryF("SHOW TABLES LIKE '$tablename'");
		return($xoopsDB->getRowsNum($result) > 0);
	}


function JobFieldExists($fieldname,$table)
	{
		global $xoopsDB;
		$result=$xoopsDB->queryF("SHOW COLUMNS FROM	$table LIKE '$fieldname'");
		return($xoopsDB->getRowsNum($result) > 0);
	}


function JobAddField($field, $table)
	{
		global $xoopsDB;
		$result=$xoopsDB->queryF("ALTER TABLE " . $table . " ADD $field;");
		return $result;
	}
	
function is_valid_email($Email = "") {
  if (ereg("[[:alnum:]]+@[[:alnum:]]+\.[[:alnum:]]+", $Email)) {
    return true;
  } else {
    return false;
  }
}


function updateHojaVida($form){
    global $xoopsDB;
    $objResponse = new xajaxResponse();
    
    
    
    if (empty($form['firstname'])){
    	$objResponse->alert('Por favor, ingrese la información de su nombre');
    	$objResponse->script("document.getElementById('firstname').focus();");
    	return $objResponse;
    }
    
    if (empty($form['genero'])){
    	$objResponse->alert('Por favor, seleccione su genero');
    	return $objResponse;
    }
    
    if (empty($form['birddate'])){
    	$objResponse->alert('Por favor, ingrese la fecha de nacimiento');
    	return $objResponse;
    }
    
    if(false == is_valid_email($form['email'])){
    	$objResponse->alert('Debe ingresar un correo válido');
    	return $objResponse;
    }
    
    /*if (0 == $form['tipodocumento']){
    	$objResponse->alert('Por favor, seleccione el tipo de documento');
    	return $objResponse;
    }*/
    
    if (1 == $form['update']){
    	$sql = "UPDATE " . $xoopsDB->prefix('jobs_resume') . " 
    	        SET name = '{$form['firstname']}', lastname = '{$form['lastname']}', sexo = '{$form['genero']}', 
    	        fechanac = '{$form['birddate']}', tipoid = '{$form['tipodocumento']}', numid = '{$form['numid']}',
    	        email = '{$form['email']}', tel = '{$form['telefono']}', tel2 = '{$form['otelefono']}',
    	        celular = '{$form['celular']}', town = '{$form['direccion']}', department = '{$form['departamento']}',
    	        ciudad = '{$form['ciudad']}', salary = '{$form['salario']}' WHERE lid = '{$form['id']}'";
    }else{
    	$sql= "INSERT INTO " . $xoopsDB->prefix('jobs_resume') . " 
    	       (name, lastname, sexo, fechanac, tipoid, numid, email, tel, tel2, celular, town, department, ciudad, salary)
    	        VALUES ('{$form['firstname']}', '{$form['lastname']}', '{$form['genero']}', '{$form['birddate']}', 
    	                '{$form['tipodocumento']}', '{$form['numid']}', '{$form['email']}', '{$form['telefono']}',
    	                '{$form['otelefono']}', '{$form['celular']}', '{$form['direccion']}', '{$form['departamento']}',
    	                '{$form['ciudad']}', '{$form['salario']}')";
    }
    //$objResponse->alert(print_r($sql, true));
    $query = $xoopsDB->query($sql);
    
    $objResponse->alert("información actualizada");
    
    updateUserExternalData($form);
    
    return $objResponse;
}

function selectCity($department, $id){
	global $xoopsDB;
	$objResponse = new xajaxResponse();
	$html = "<select name='ciudad' id='ciudad'>";
	$html .= "<option value='0'></option>";
	
	$sql = "SELECT * FROM " . $xoopsDB->prefix('jobs_city') . " WHERE iddepartment = '{$department}' ORDER BY name";
	$query = $xoopsDB->query($sql);
	while ($data = $xoopsDB->fetchArray($query)) {
		$html .= "<option value='{$data['idcity']}'>{$data['name']}</option>";
	}
	$html .= "</select>";
	
	$objResponse->assign($id, 'innerHTML', $html);
	
	return $objResponse;
}

function diaDiferencia($fecha1, $fecha2){
	$datetime1 = new DateTime(date('Y-m-d', $fecha1));
	$datetime2 = new DateTime(date('Y-m-d', $fecha2));
	$intervalo = $datetime1->diff($datetime2);
	
	return $intervalo->format('%y a&ntilde;os y %m meses');
}


function updateUserExternalData($data){
	include_once (XOOPS_ROOT_PATH."/modules/jobs/conexion.php");
	
	$conn= conexion();  // crea una variable que almacene la conexion 
	$sql = mysql_query("SELECT * FROM egresados WHERE CEDULA='{$data['numid']}'",$conn);
	
	if (0 < mysql_num_rows($sql)){
		$fila = mysql_fetch_array($sql);
		$date = date('Y-m-d');
		$name = $data['lastname'] . " " . $data['firstname'];
		$name = trim($name);
		$sql = "UPDATE egresados SET NOMBRE = '{$name}', FECHA_NACIMIENTO = '{$data['birddate']}', DIRECCION1 = '{$data['direccion']}',
		        TELEFONO1 = '{$data['telefono']}', CELULAR = '{$data['celular']}', EMAIL = '{$data['email']}',
		        MUNICIPIO_RESIDENCIA = '{$data['ciudad']}', DEPARTAMENTO_RESIDE = '{$data['departamento']}',
		        FECHA_ACTUALIZACION = '{$date}' WHERE CEDULA = '{$data['numid']}'";
		mysql_query($sql);
	}
	
	
	
}

function insertUser($numid){
    global $xoopsDB, $xoopsConfig, $xoopsUser, $xoopsTheme, $xoopsLogger, $xoopsModule, $xoopsModuleConfig, $mydirname;
    
    $sql= "INSERT INTO " . $xoopsDB->prefix('jobs_resume') . " (numid) VALUES ('{$numid}')";
    $xoopsDB->query($sql);
    echo $sql;
    $userid = $xoopsDB->getInsertId();
    
    return $userid;
    
}

function formUser($user){
	global $xoopsDB, $xoopsConfig, $xoopsUser, $xoopsTheme, $xoopsLogger, $xoopsModule, $xoopsModuleConfig, $mydirname;
	
	
	include_once (XOOPS_ROOT_PATH."/modules/jobs/conexion.php");
	
	$conn= conexion();  // crea una variable que almacene la conexion 
	$sql = mysql_query("SELECT * FROM egresados WHERE CEDULA='$user'",$conn);
	$fila = mysql_fetch_array($sql);
	
	if (0 < count($fila)) {
		$sql = "SELECT * FROM " . $xoopsDB->prefix('jobs_resume') . " WHERE numid = '{$user}'";
		$query = $xoopsDB->query($sql);
		$data = $xoopsDB->fetchArray($query);
		
		$iduser = $data['lid'];
		
		if (1 < count($data)) {
			$update = 1;
			
		}else{
            //$iduser = insertUser($fila['CEDULA']);
            //$update = 1;
        }
        
		$data['name'] = $fila['NOMBRE'];
			$data['numid'] = $fila['CEDULA'];
			$data['tipoid'] = $fila['TIPODCTO'];
			$data['fechanac'] = $fila['FECHA_NACIMIENTO'];
			$data['town'] = $fila['DIRECCION1'];
			$data['tel'] = $fila['TELEFONO1'];
			$data['celular'] = $fila['CELULAR'];
			$data['email'] = $fila['EMAIL'];
			$data['ciudad'] = $fila['MUNICIPIO_RESIDENCIA'];
			$data['department'] = $fila['DEPARTAMENTO_RESIDE'];
            $ext = $data['foto'];
	}else {
		exit();
	}
	require_once(XOOPS_ROOT_PATH.'/Frameworks/xajax/xajax_core/xajax.inc.php');
	
	$xajax = new xajax();
	$xajax->registerFunction("updateHojaVida");
	$xajax->registerFunction("showExpLaboral");
	$xajax->registerFunction("updateLaboralEx");
	$xajax->registerFunction("confirmDelEstudios");
	$xajax->registerFunction("delEstudios");
	$xajax->registerFunction("showEstudios");
	$xajax->registerFunction("addEstudio");
    $xajax->registerFunction("delExpLaboral");
	$xajax->registerFunction("confirmDelExpLaboral");
	$xajax->registerFunction("clearInputEstudio");
	$xajax->registerFunction("addCompetencia");
	$xajax->registerFunction("delCompetencia");
	$xajax->registerFunction("showCompetencia");
	$xajax->registerFunction("clearcompetencia");
	$xajax->registerFunction("confirmDelCompetencia");
	$xajax->registerFunction("addIdioma");
	$xajax->registerFunction("showIdioma");
	$xajax->registerFunction("delIdioma");
	$xajax->registerFunction("confirmDelIdioma");
	$xajax->registerFunction("clearIdioma");
	$xajax->registerFunction("addConocimiento");
	$xajax->registerFunction("showConocimiento");
	$xajax->registerFunction("delConocimiento");
	$xajax->registerFunction("confirmDelConocimiento");
	$xajax->registerFunction("clearConocimiento");
	//$xajax->setFlag("debug", true);
	$xajax->processRequest();

	 echo '<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar/dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
	<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar/dhtmlgoodies_calendar.js?random=20060118"></script>';
	?>
	<link href="<?php echo XOOPS_URL . "/modules/" . $mydirname; ?>/jquery-ui/css/ui-lightness/jquery-ui-1.8.6.custom.css" rel="stylesheet" type="text/css"/>
  <script src="<?php echo XOOPS_URL . "/modules/" . $mydirname; ?>/jquery-ui/js/jquery-1.4.2.min.js"></script>
  <script src="<?php echo XOOPS_URL . "/modules/" . $mydirname; ?>/jquery-ui/js/jquery-ui-1.8.6.custom.min.js"></script>
  <script src="<?php echo XOOPS_URL . "/modules/" . $mydirname; ?>/jquery-ui/js/jquery.uploadify.v2.1.0.min.js"></script>
  <script type="text/javascript" src="<?php echo XOOPS_URL . "/modules/" . $mydirname; ?>/swfobject.js"></script>
  
  <script>
  jQuery.noConflict();
  jQuery(document).ready(function() {
    jQuery("#accordion").accordion();
  });
  </script>

<script type="text/javascript">// <![CDATA[
jQuery(document).ready(function() {
	jQuery('#fileInput').uploadify({
		'uploader'  : 'uploadify.swf',
		'script'    : 'uploader.php',
		'cancelImg' : 'cancel.png',
		'auto'      : true,
		'folder'    : 'uploads',
		'scriptData' : {'user': jQuery("#userdata").val()},
		'onComplete': function(event, queueID, fileObj, response, data) {
            document.getElementById('fotosWrapper').innerHTML = '';
 		    jQuery('#fotosWrapper').append(response);
		}
	});
});
// ]]>
</script>
	
	<form name='userForm' id='userForm' method='post' action='<?php echo $_SERVER['PHP_SELF']?>' >
	<div class="demo">
	    <div id="accordion">
		<h3><a href="#">Informaci&oacute;n Personal</a></h3>
	        <div>
	            <table width="500">
	                <tr>
	                    <td colspan="1" rowspan="4">
                            <?php
                            if(!empty($iduser)){
                                if(file_exists("uploads/{$iduser}.{$ext}")){
                                //if(file_exists(XOOPS_URL . "/modules/" . $mydirname . "uploads/" . $iduser . ".png")){
                                    echo "<img src='uploads/{$iduser}.{$ext}' width='100' height='100'>";
                                }else{
                                    echo "<img src='uploads/nophoto.png' width='100' height='100'>";
                                }
                            }
                            ?>
                        </td>
	                    <td rowspan="5"></td>
	                    <td></td>
	                    <td></td>
	                </tr>
	                <tr>
	                    <td><b>Nombres:</b></td>
	                    <td><input type="text" name="firstname" id="firstname" value="<?php echo $data['name']; ?>"></td>
	                </tr>
	                <tr>
	                    <td><b>Apellidos:</b></td>
	                    <td><input type="text" name="lastname" id="lastname"  value="<?php echo $data['lastname']; ?>"></td>
	                </tr>
	                <tr>
	                    <td><b>Genero:</b></td>
	                    <td><input type="radio" name="genero" id="gfemenino" value="femenino" <?php if ('femenino' == $data['sexo']){ echo "selected";}?>>femenino</td>
	                </tr>
	                <tr>
	                    <td>
                        <?php
                            if(!empty($iduser)){
                        ?>
                        <input type="hidden" size="25" name="userdata" id="userdata" value='<?php echo $iduser; ?>' />
                        <input type="file" name="fileInput" id="fileInput" />
                        <div id="fotosWrapper"></div>
                        <?php
                        }
                        ?>
                        </td>
	                    <td></td>
	                    <td><input type="radio" name="genero" id="gmasculino" value="masculino" <?php if ('masculino' == $data['sexo']){ echo "selected";}?>>masculino</td>
	                </tr>
	                <tr>
	                    <td></td>
	                    
	                    <td colspan="2">Fecha de nacimiento</td>
	                    <td><input type="text" name="birddate" id="birddate"  value="<?php echo $data['fechanac']; ?>" onclick="displayCalendar(document.getElementById('birddate'),'yyyy-mm-dd',this)"></td>
	                </tr>
	                <tr>
	                    <td></td>
	                    
	                    <td colspan="2">Tipo documento</td>
	                    <td>
	                        <select name="tipodocumento" id="tipodocumento">
	                            <option value="0">Seleccione<option>
	                            <option value="TI">Tarjeta de identidad</option>
	                            <option value="CC">C&eacute;dula</option>
	                            <option value="RC">Residencia</option>
	                        </select>
	                    </td>
	                </tr>
	                <tr>
	                    <td></td>
	                    <td colspan="2">N&uacute;mero de documento</td>
	                    <td><input type="text" name="numid" id="numid" value="<?php echo $data['numid']; ?>" <?php if (isset($data['numid'])) {echo "readonly";}?>></td>
	                </tr>
	                 <tr>
	                    <td></td>
	                    <td colspan="2">Correo electr&oacute;nico</td>
	                    <td><input type="text" name="email" id="email"  value="<?php echo $data['email']; ?>"></td>
	                </tr>
	                <tr>
	                    <td></td>
	                    <td colspan="2">Tel&eacute;fono</td>
	                    <td><input type="text" name="telefono" id="telefono"  value="<?php echo $data['tel']; ?>"></td>
	                </tr>
	                <tr>
	                    <td></td>
	                    <td colspan="2">Otro tel&eacute;fono</td>
	                    <td><input type="text" name="otelefono" id="otelefono"  value="<?php echo $data['tel2']; ?>"></td>
	                </tr>
	                <tr>
	                    <td></td>
	                    <td colspan="2">Celular</td>
	                    <td><input type="text" name="celular" id="celular"  value="<?php echo $data['celular']; ?>"></td>
	                </tr>
	                <tr>
	                    <td></td>
	                    <td colspan="2">Direcci&oacute;n</td>
	                    <td><input type="text" name="direccion" id="direccion"  value="<?php echo $data['town']; ?>"></td>
	                </tr>
	                <tr>
	                    <td></td>
	                    <td colspan="2">Departamento</td>
	                    <td><input type="text" name="departamento" id="departamento" value="<?php echo $data['department']; ?>">
	                        <!-- <select name="departamento" id="departamento" onchange="xajax_selectCity(document.getElementById(this.id).value, 'selCity')">
	                            <option value="0"></option>
	                            <?php 
	                                /*$sql = "SELECT * FROM " . $xoopsDB->prefix('jobs_department') . " ORDER BY name";
	                                $query = $xoopsDB->query($sql);
	                                while ($datad = $xoopsDB->fetchArray($query)) {
	                                    echo "<option value='{$datad['iddepartment']}'";
	                                    if ($data['department'] == $datad['iddepartment']) {
	                                    	echo " selected";
	                                    }
	                                    echo ">{$datad['name']}</option>";
	                                }*/
	                            ?>
	                        </select> -->
	                    </td>
	                </tr>
	                <tr>
	                    <td></td>
	                    <td colspan="2">Ciudad</td>
	                    <td id="selCity"><input type="text" name="ciudad" id="ciudad" value="<?php echo $data['ciudad']; ?>" >
	                        <!--  <select name="ciudad" id="ciudad">
	                            <option value="0"></option>
	                            <?php 
	                       /*         if (1 == $update) {
	                                	$sql = "SELECT * FROM " . $xoopsDB->prefix('jobs_city') . " WHERE  WHERE iddepartment = '{$data['department']}' ORDER BY name";
	                                	$query = $xoopsDB->query($sql);
										while ($datac = $xoopsDB->fetchArray($query)) {
											echo  "<option value='{$datac['idcity']}'";
											if ($data['ciudad'] == $datac['idcity']) {
												echo " selected";
											}
											echo ">{$datac['name']}</option>";
										}
	                                }*/
	                            ?>
	                        </select>-->
	                    </td>
	                </tr>
	                <tr>
	                    <td></td>
	                    <td colspan="2">Aspiraci&oacute;n salarial</td>
	                    <td><input type="text" name="salario" id="salario"  value="<?php echo $data['salary']; ?>"></td>
	                </tr>
	                <tr>
	                    <td colspan="4" align="center">
	                    <input type="hidden" name="id" id="id" value="<?php echo $iduser; ?>">
	                    <input type="hidden" name="update" id="update" value="<?php echo $update; ?>">
	                    <input type="button" name="savePersonal" id="savePersonal" value="Guardar informaci&oacute;n" onclick="xajax_updateHojaVida(xajax.getFormValues('userForm'))"></td>
	                </tr>
	            </table>
	            </form>
	        </div>
	        <h3><a href="#">Informaci&oacute;n Laboral</a></h3>
    		<div>
    		    <div id="infoLabora">
    		    <table border="1" width="500">
    		        <tr>
    		            <td><b>Empresa</b></td><td><b>Cargo</b></td><td><b>Experiencia</b></td><td><b>Acci&oacute;n</b></td>
    		        </tr>
    		        <?php 
    		            $id = (isset($id)) ? $id : 0;
    		            $sql = "SELECT * FROM " . $xoopsDB->prefix('jobs_laboralexp') . " WHERE user = '{$iduser}'";
    		            $query = $xoopsDB->query($sql);
    		            
    		            while ($data = $xoopsDB->fetchArray($query)) {
    		                ?>
    		                <tr id="exp-<?php echo $data['id'] ?>">
    		                    <td><?php echo $data['empresa'] ?></td>
    		                    <td><?php echo $data['cargo'] ?></td>
    		                    <?php 
    		                    $fechafin = (0 == $data['fechafin']) ? time() : $data['fechafin'];
    		                    ?>
    		                    <td><?php echo diaDiferencia($data['fechainicio'], $fechafin) ?></td>
    		                    <td><a href="javascript:;" onclick="xajax_delExpLaboral('<?php echo $data['id']; ?>')">Borrar</a></td>
    		                </tr>
    		                <?php 
    		            }
    		        ?>
    		    </table>
    		    </div>
    		    <br>
    		    <br>
    		    <table style="width:500px;" align="center">
    		        <tr>
    		            <td><b>Empresa</b>
    		            <td colspan="2"><input type="text" name="empresa" id="empresa"></td>
    		        </tr>
    		        <tr>
    		            <td><b>Cargo</b>
    		            <td colspan="2"><input type="text" name="cargo" id="cargo"></td>
    		        </tr>
    		        <tr>
    		            <td><b>Sector</b>
    		            <td colspan="2">
    		            <select name="sector" id="sector">
    		                <option value="0"></option>
    		                <?php 
    		                    $sql = "SELECT * FROM " . $xoopsDB->prefix('jobs_sectorempresa') . " ORDER BY nombre";
    		                    $query = $xoopsDB->query($sql);
    		                    while ($data = $xoopsDB->fetchArray($query)) {
    		                        echo "<option value='{$data['id']}'>{$data['nombre']}</option>";
    		                    }
    		                ?>
    		            </select>
    		            </td>
    		        </tr>
    		        <tr>
    		            <td><b>Fecha Inicio</b></td>
    		            <td>
    		                <select name="ainicio" id="ainicio">
    		                    <option value="0">A&ntilde;o</option>
    		                    <?php 
    		                        $lyear = 20;
    		                        $pyear = date("Y");
    		                        for ($i = $lyear; $i >= 0; $i--){
    		                            echo "<option value='{$pyear}'>{$pyear}</option>";
    		                            $pyear--;
    		                        }
    		                    ?>
    		                </select>
    		            </td>
    		            <td>
    		                <select name="minicio" id="minicio">
    		                    <option value="0">Mes</option>
    		                    <?php 
    		                        for ($i = 1; $i <= 12; $i++){
    		                            echo "<option value='{$i}'>{$i}</option>";
    		                        }
    		                    ?>
    		                </select>
    		            </td>
    		        </tr>
    		        <tr>
    		            <td><b>Fecha Terminaci&oacute;n</b></td>
    		            <td>
    		                <select name="afin" id="afin">
    		                    <option value="0">Actualmente</option>
    		                    <?php 
    		                        $lyear = 20;
    		                        $pyear = date("Y");
    		                        for ($i = $lyear; $i >= 0; $i--){
    		                            echo "<option value='{$pyear}'>{$pyear}</option>";
    		                            $pyear--;
    		                        }
    		                    ?>
    		                </select>
    		            </td>
    		            <td>
    		                <select name="mfin" id="mfin">
    		                    <option value="0">Actualmente</option>
    		                    <?php 
    		                        for ($i = 1; $i <= 12; $i++){
    		                            echo "<option value='{$i}'>{$i}</option>";
    		                        }
    		                    ?>
    		                </select>
    		            </td>
    		        </tr>
                    <tr>
                        <td colspan="3">&nbsp;</td>
                    </tr>
                    <tr>
                        <td colspan="3"><b>Funciones del cargo</b></td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <textarea rows="4" cols="40" name="funciones" id="funciones"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3"><b>Logros</b></td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <textarea rows="4" cols="40" name="logro" id="logro"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td><b>&Aacute;rea del cargo</b></td>
                        <td colspan="2">
                            <select name="areacargo" id="areacargo">
    		                <option value="0"></option>
    		                <?php 
    		                    $sql = "SELECT * FROM " . $xoopsDB->prefix('jobs_areacargo') . " ORDER BY nombre";
    		                    $query = $xoopsDB->query($sql);
    		                    while ($data = $xoopsDB->fetchArray($query)) {
    		                        echo "<option value='{$data['id']}'>{$data['id']}</option>";
    		                    }
    		                ?>
    		            </select>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3" align="center">
                        <input type="hidden" name="idlabora" id="idlabora" value="0">
                        <input type="hidden" name="updatelabora"  id="updatelabora" value="0" >
                        <input type="button" name="guardarlabora" id="guardarlabora" value="Guardar informaci&oacute;n" onclick="xajax_updateLaboralEx('<?php echo $iduser;?>', document.getElementById('empresa').value, document.getElementById('cargo').value, document.getElementById('sector').value, document.getElementById('ainicio').value, document.getElementById('minicio').value, document.getElementById('afin').value,document.getElementById('mfin').value,document.getElementById('funciones').value,document.getElementById('logro').value,document.getElementById('areacargo').value,document.getElementById('updatelabora').value, document.getElementById('idlabora').value)"></td>
                    </tr>
    		    </table>
    		</div>
	        <h3><a href="#">Estudios</a></h3>
            <div>
                <div id="nivelEstudios">
                 <table border="1" width="500">
    		        <tr>
    		            <td><b>Nivel de estudio</b></td><td><b>T&iacute;tulo</b></td><td><b>instituci&oacute;n</b></td><td><b>Acci&oacute;n</b></td>
    		        </tr>
    		        <?php 
    		            $id = (isset($id)) ? $id : 0;
    		            $sql = "SELECT eg.*, n.nombre as nivel FROM " . $xoopsDB->prefix('jobs_estudiosgraduado') . " eg join " . $xoopsDB->prefix('jobs_nivelestudio') . " n ON n.id = eg.nivelestudio WHERE user = '{$iduser}'";
    		            $query = $xoopsDB->query($sql);
    		            
    		            while ($data = $xoopsDB->fetchArray($query)) {
    		                ?>
    		                <tr id="exp-<?php echo $data['id'] ?>">
    		                    <td><?php echo $data['nivel'] ?></td>
    		                    <td><?php echo $data['titulo'] ?></td>
    		                    <td><?php echo $data['institucion'] ?></td>
    		                    <td><a href="javascript:;" onclick="xajax_delEstudios('<?php echo $data['id']; ?>');">Borrar</a></td>
    		                </tr>
    		                <?php 
    		            }
    		        ?>
    		    </table>
                </div>
    		    <hr>
    		    <table align="center" style="width:500px;" border="0">
    		        <tr>
    		            <td><b>Nivel de estudios</b></td>
    		            <td colspan="2">
    		                <select name="nivelestudio" id="nivelestudio">
    		                <option value="0"></option>
    		                <?php 
    		                    $sql = "SELECT * FROM " . $xoopsDB->prefix('jobs_nivelestudio') . " ORDER BY nombre";
    		                    $query = $xoopsDB->query($sql);
    		                    while ($data = $xoopsDB->fetchArray($query)) {
    		                        echo "<option value='{$data['id']}'>{$data['nombre']}</option>";
    		                    }
    		                ?>
    		            </select>
    		            </td>
    		        </tr>
    		        <tr>
    		            <td><b>T&iacute;tulo obtenido</b></td>
    		            <td colspan="2">
    		                 <input type="text" name="titulo" id="titulo" value="">
    		            </td>
    		        </tr>
    		        <tr>
    		            <td><b>Instituci&oacute;n</b></td>
    		            <td colspan="2">
    		                 <input type="text" name="institucion" id="institucion" value="">
    		            </td>
    		        </tr>
    		        <tr>
    		            <td><b>Fecha finalizaci&oacute;n</b></td>
    		            <td>
    		                <select name="afine" id="afine">
    		                    <option value="0"></option>
    		                    <?php 
    		                        $lyear = 20;
    		                        $pyear = date("Y");
    		                        for ($i = $lyear; $i >= 0; $i--){
    		                            echo "<option value='{$pyear}'>{$pyear}</option>";
    		                            $pyear--;
    		                        }
    		                    ?>
    		                </select>
    		            </td>
    		            <td>
    		                <select name="mfine" id="mfine">
    		                    <option value="0"></option>
    		                    <?php 
    		                        for ($i = 1; $i <= 12; $i++){
    		                            echo "<option value='{$i}'>{$i}</option>";
    		                        }
    		                    ?>
    		                </select>
    		            </td>
    		        </tr>
    		        <tr>
    		            <td><input type="button" name="guardarestudio"  id="guardarestudio" value="Guardar estudio" onclick="xajax_addEstudio('<?php echo $iduser;?>', document.getElementById('nivelestudio').value, document.getElementById('titulo').value, document.getElementById('institucion').value, document.getElementById('afine').value, document.getElementById('mfine').value)"></td>
    		        </tr>
    		    </table>
            </div>
	        <h3><a href="#">Competencias</a></h3>
    		<div>
                <div id="showCompetencia">
    		    <table border="1" width="500">
    		        <tr>
    		            <td><b>Competencia</b></td><td><b>Acci&oacute;n</b></td>
    		        </tr>
    		        <?php 
    		            $id = (isset($id)) ? $id : 0;
    		            $sql = "SELECT * FROM " . $xoopsDB->prefix('jobs_competencia') . " WHERE user = '{$iduser}'";
    		            $query = $xoopsDB->query($sql);
    		            
    		            while ($data = $xoopsDB->fetchArray($query)) {
    		                ?>
    		                <tr id="exp-<?php echo $data['id'] ?>">
    		                    <td><?php echo $data['competencia'] ?></td>
    		                    
    		                    <td><a href="javascript:;" onclick="xajax_delCompetencia('<?php echo $data['id'] ?>')">Borrar</a></td>
    		                </tr>
    		                <?php 
    		            }
    		        ?>
    		    </table>
                </div>
    		    <hr>
    		    <br>
    		    <table>
    		        <tr>
    		            <td><b>Competencia</b></td>
    		            <td><input type="text" name="competencia"  id="competencia" value=""></td>
    		        </tr>
                    <tr>
    		            <td colspan="2" align="center">&nbsp;</td>
    		        </tr>
    		        <tr>
    		            <td colspan="2" align="center"><input type="button" name="guardarcompetencia" id="guardarcompetencia" value="Guardar competencia" onclick="xajax_addCompetencia('<?php echo $iduser;?>', document.getElementById('competencia').value)"></td>
    		        </tr>
    		    </table>
    		</div>
	        <h3><a href="#">Conocimientos</a></h3>
    		<div>
                <div id="showConocimiento">
    		    <table border="1" width="500">
    		        <tr>
    		            <td><b>Programa</b></td><td><b>Nivel</b></td><td><b>Acci&oacute;n</b></td>
    		        </tr>
    		        <?php 
    		            $id = (isset($id)) ? $id : 0;
    		            $sql = "SELECT * FROM " . $xoopsDB->prefix('jobs_conocimientoprograma') . " WHERE user = '{$iduser}'";
    		            $sql = "SELECT i.*, n.nombre FROM " . $xoopsDB->prefix('jobs_conocimientoprograma') . " i join " . $xoopsDB->prefix('jobs_nivelconocimiento') . " n ON n.id = i.nivel WHERE user = '{$iduser}'";
    		            $query = $xoopsDB->query($sql);
    		            
    		            while ($data = $xoopsDB->fetchArray($query)) {
    		                ?>
    		                <tr id="exp-<?php echo $data['id'] ?>">
    		                    <td><?php echo $data['conocimiento 	'] ?></td>
    		                    <td><?php echo $data['nombre'] ?></td>
    		                    
    		                    <td><a href="javascript:;" onclick="xajax_delConocimiento('<?php echo $data['id'] ?>')">Borrar</a></td>
    		                </tr>
    		                <?php 
    		            }
    		        ?>
    		    </table>
                </div>
    		    <hr>
    		    <br>
    		    <table>
    		        <tr>
    		            <td><b>Programa</b></td>
    		            <td><input type="text" name="conocimiento"  id="conocimiento" value=""></td>
    		        </tr>
    		        <tr>
    		            <td><b>Nivel</b></td>
    		            <td>
    		                <select name="nivelconocimiento" id="nivelconocimiento">
    		                <option value="0"></option>
    		                <?php 
    		                    $sql = "SELECT * FROM " . $xoopsDB->prefix('jobs_nivelconocimiento') . " ORDER BY nombre";
    		                    $query = $xoopsDB->query($sql);
    		                    while ($data = $xoopsDB->fetchArray($query)) {
    		                        echo "<option value='{$data['id']}'>{$data['nombre']}</option>";
    		                    }
    		                ?>
    		            </select>
    		            </td>
    		        </tr>
    		        <tr>
    		            <td colspan="2"><input type="button" name="guardarconocimiento" id="guardarconocimiento" value="Guardar Conocimiento" onclick="xajax_addConocimiento('<?php echo $iduser ?>', document.getElementById('conocimiento').value, document.getElementById('nivelconocimiento').value);"></td>
    		        </tr>
    		    </table>
    		    <hr>
    		    <br>
                <div id="showIdioma">
                <table border="1" width="500">
    		        <tr>
    		            <td><b>Idioma</b></td><td><b>Nivel</b></td><td><b>Acci&oacute;n</b></td>
    		        </tr>
    		        <?php 
    		            $id = (isset($id)) ? $id : 0;
    		            $sql = "SELECT i.*, n.nombre FROM " . $xoopsDB->prefix('jobs_conocimientoidioma') . " i join " . $xoopsDB->prefix('jobs_nivelidioma') . " n ON n.id = i.nivel WHERE user = '{$iduser}'";
    		            $query = $xoopsDB->query($sql);
    		            
    		            while ($data = $xoopsDB->fetchArray($query)) {
    		                ?>
    		                <tr id="exp-<?php echo $data['id'] ?>">
    		                    <td><?php echo $data['idioma'] ?></td>
    		                    <td><?php echo $data['nombre'] ?></td>
    		                    
    		                    <td><a href="javascript:;" onclick="xajax_delIdioma('<?php $data['id'] ?>')">Borrar</a></td>
    		                </tr>
    		                <?php 
    		            }
    		        ?>
    		    </table>
                
                </div>
    		    <hr>
    		    <br>
    		    <table>
    		        <tr>
    		            <td><b>Idioma</b></td>
    		            <td><input type="text" name="idioma"  id="idioma" value=""></td>
    		        </tr>
    		        <tr>
    		            <td><b>Nivel</b></td>
    		            <td>
    		                <select name="nivelidioma" id="nivelidioma">
    		                <option value="0"></option>
    		                <?php 
    		                    $sql = "SELECT * FROM " . $xoopsDB->prefix('jobs_nivelidioma') . " ORDER BY nombre";
    		                    $query = $xoopsDB->query($sql);
    		                    while ($data = $xoopsDB->fetchArray($query)) {
    		                        echo "<option value='{$data['id']}'>{$data['nombre']}</option>";
    		                    }
    		                ?>
    		            </select>
    		            </td>
    		        </tr>
    		        <tr>
    		            <td colspan="2"><input type="button" name="guardaridioma" id="guardaridioma" value="Guardar Idioma" onclick="xajax_addIdioma('<?php echo $iduser ?>', document.getElementById('idioma').value, document.getElementById('nivelidioma').value);"></td>
    		        </tr>
    		    </table>
    		</div>
	    </div>
	 
	
	
	<?php 
	$Xjavapath=XOOPS_URL.'/Frameworks/xajax';
$xajaxjava=$xajax->getJavascript($Xjavapath);
echo $xajaxjava;
}


function updateLaboralEx($user, $empresa, $cargo, $sector, $ainicio, $minicio, $afin, $mfin, $funciones, $logros, $area, $update = 0, $id = 0){
    global $xoopsDB;
    $objResponse = new xajaxResponse();
    
    if (!empty($user)){
    	if (empty($empresa)){
    		$objResponse->alert("Debe ingresar la información de la empresa");
    		return $objResponse;
    	}
    	
    	if (empty($cargo)){
    		$objResponse->alert("Debe ingresar la informacion del cargo");
    		return $objResponse;
    	}
    	
    	if (empty($ainicio) || empty($minicio)){
    		$objResponse->alert("Debe registrar una fecha de ingreso");
    		return $objResponse;
    	}
    	
    	$fechai = mktime(0, 0, 0, $minicio, 1, $ainicio);
    	
    	if (0 == $afin || 0 == $mfin){
    		$fechaf = 0;
    	}else {
    		$fechaf = mktime(0, 0, 0, $mfin, 1, $afin);
    	}
    	
    	if (1 == $update){
    		
    		$sql = "UPDATE " . $xoopsDB->prefix('jobs_laboralexp') . " SET 
    		        empresa = '{$empresa}', cargo = '{$cargo}', sector = '{$sector}', 
    		        fechainicio = '{$fechai}', fechafin = '{$fechaf}', funciones = '{$funciones}', 
    		        logros = '{$logros}', area = '{$area}'
    		        WHERE id = '{$id}' AND user = '{$user}'";
    	}else{
    		$sql = "INSERT INTO " . $xoopsDB->prefix('jobs_laboralexp') . " 
    		        (empresa, cargo, sector, fechainicio, fechafin, funciones, logros, area, user) 
    		        VALUES ('{$empresa}', '{$cargo}', '{$sector}', '{$fechai}', '{$fechaf}', 
    		        '{$funciones}', '{$logros}','{$area}', '{$user}')";
    	}
    	$xoopsDB->query($sql);
    	$objResponse->alert($sql);
    	$objResponse->script("xajax_showExpLaboral('{$user}')");
    }
    
    
    return $objResponse;
}


function showExpLaboral($user = 0){
	global $xoopsDB;
    $objResponse = new xajaxResponse();
    
    $html = "<table>";
    $html .= "<tr><td><b>Empresa</b></td><td><b>Cargo</b></td><td><b>Experiencia</b></td><td><b>Acci&oacute;n</b></td>
    		  </tr>";
    
    $sql = "SELECT * FROM " . $xoopsDB->prefix('jobs_laboralexp') . " WHERE user = '{$user}'";
    $query = $xoopsDB->query($sql);
    
	while ($data = $xoopsDB->fetchArray($query)) {
    		               
    	$html .= "<tr id=\"exp-{$data['id']}\">";
    	$html .= "<td>{$data['empresa']}</td>";
    	$html .= "<td>{$data['cargo']}</td>";
    	$fechafin = (0 == $data['fechafin']) ? time() : $data['fechafin'];
    	$experiencia = diaDiferencia($data['fechainicio'], $fechafin);
    	$html .= "<td>{$experiencia}</td>";
    	$html .= "<td><a href=\"javascript:;\" onclick=\"xajax_delExpLaboral('{$data['id']}')\">Borrar</a></td>";
    	$html .= "</tr>";
    		                
    }
    
    $html .="</table>";
    
    $objResponse->assign('infoLabora', 'innerHTML', $html);
    
    return $objResponse;
}

function addEstudio($user = 0, $nivelestudio, $titulo, $institucion, $afine, $mfine){
    global $xoopsDB;
    $objResponse = new xajaxResponse();
    
    if(0 != $user){
        $sql = "INSERT INTO " . $xoopsDB->prefix('jobs_estudiosgraduado') . " (user, nivelestudio, titulo, institucion, year, mes) 
                 VALUES ('{user}', '{$nivelestudio}', '{$titulo}', '{$institucion}', '{$afine}', '{$mfine}')";
        $xoopsDB->query($sql);
        
        $objResponse->script("xajax_showEstudios('{$data['user']}');");
        $objResponse->script("xajax_clearInputEstudio();");
    }
    
    return $objResponse;
}


function showEstudios($user = 0){
    global $xoopsDB;
    $objResponse = new xajaxResponse();
    
    $html = "<table border=\"1\" width=\"500\">
    		        <tr>
    		            <td><b>Nivel de estudio</b></td><td><b>T&iacute;tulo</b></td><td><b>instituci&oacute;n</b></td><td><b>Acci&oacute;n</b></td>
    		        </tr>"; 
    		            
    		            $sql = "SELECT eg.*, n.nombre as nivel FROM " . $xoopsDB->prefix('jobs_estudiosgraduado') . " eg join " . $xoopsDB->prefix('jobs_nivelestudio') . " n ON n.id = eg.nivelestudio WHERE user = '{$iduser}' ";
    		            $query = $xoopsDB->query($sql);
    		            
    		            while ($data = $xoopsDB->fetchArray($query)) {
    		                
    		                $html .= "<tr id=\"exp-{$data['id']}\">
    		                    <td>{$data['nivel']}</td>
    		                    <td>{$data['titulo']}</td>";
                                
    		                 $html .="<td>{$data['institucion']}</td>
    		                    <td><a href=\"javascript:;\" onclick=\"xajax_delEstudios('{$data['id']}')\">Borrar</a></td>
    		                </tr>";
    		                
    		            }
                
    		    $html .= "</table>";
    
    $objResponse->assign('nivelEstudios', 'innerHTML', $html);
    
    return $objResponse;
}

function delEstudios($id = 0){
    $objResponse = new xajaxResponse();
    
    $objResponse->confirmCommands(0, "Realmente desea eliminar el registro?");
    $objResponse->script("xajax_confirmDelEstudios($id)");
    
    return $objResponse;
}

function clearInputEstudio(){
    $objResponse = new xajaxResponse();
    
    $objResponse->assign('titulo', 'value', '');
    $objResponse->assign('institucion', 'value', '');
    $objResponse->addScript("document.getElementById('nivelestudio').selectedIndex = 0");
    $objResponse->addScript("document.getElementById('afine').selectedIndex = 0");
    $objResponse->addScript("document.getElementById('mfine').selectedIndex = 0");
    
    return $objResponse;
}

function confirmDelEstudios($id = 0){
    global $xoopsDB;
    $objResponse = new xajaxResponse();

    $sql = "SELECT * FROM " . $xoopsDB->prefix('jobs_estudiosgraduado') . " WHERE id = '{$id}'";
    $query = $xoopsDB->query($sql);
    $data = $xoopsDB->fetchArray($query);
    
    $sql = "DELETE FROM ". $xoopsDB->prefix('jobs_estudiosgraduado') . " WHERE id = '{$id}'";
    $xoopsDB->query($sql);
    
    $objResponse->script("xajax_showEstudios('{$data['user']}');");
    
    return $objResponse;
}


function putLaboral($id){
	global $xoopsDB;
	$objResponse = new xajaxResponse();
	
	if (!empty($id)) {
		$sql = "SELECT * FROM " . $xoopsDB->prefix('jobs_laboralexp') . " WHERE id = '{$id}'";
		$query = $xoopsDB->query($sql);
		$data = $xoopsDB->fetchArray($query);
		
		$sql = "SELECT * FROM " . $xoopsDB->prefix('jobs_sectorempresa') . " ORDER BY nombre";
		$query = $xoopsDB->query($sql);
		
		$row = 0;
		while ($datasector = $xoopsDB->fetchArray($query)) {
			$row++;
			if ($datasector['id'] == $data['sector']) {
				$objResponse->script("docuemnt.getElementById('').selectedIndex = {$row}");
				break;
			}
		}
		
		/*$sql = "SELECT * FROM " . $xoopsDB->prefix('jobs_laboralexp') . " ORDER BY nombre";
		$query = $xoopsDB->query($sql);
		
		$row = 0;
		while ($datasector = $xoopsDB->fetchArray($query)) {
			$row++;
			if ($datasector['id'] == $data['sector']) {
				$objResponse->script("docuemnt.getElementById('').selectedIndex = {$row}");
				break;
			}
		}*/
		
		$objResponse->assign('empresa', 'innerHTML', $data['empresa']);
		$objResponse->assign('empresa', 'innerHTML', $data['cargo']);
		$ainicio = date("Y");
		$objResponse->assign('empresa', 'innerHTML', $data['empresa']);
		
		
	}
	
	return $objResponse;
}

function delExpLaboral($id){
	$objResponse = new xajaxResponse();
	
	$objResponse->confirmCommands(0, "Realmente desea eliminar el registro?");
	$objResponse->script("xajax_confirmDelExpLaboral('{$id}')");
	
	return $objResponse;
}

function clearexpLaboral(){
    $objResponse = new xajaxResponse();
    
    $objResponse->assign('empresa', 'value', '');
    $objResponse->assign('cargo', 'value', '');
    $objResponse->assign('funciones', 'value', '');
    $objResponse->assign('logro', 'value', '');
    $objResponse->addScript("document.getElementById('sector').selectedIndex = 0");
    $objResponse->addScript("document.getElementById('ainicio').selectedIndex = 0");
    $objResponse->addScript("document.getElementById('minicio').selectedIndex = 0");
    $objResponse->addScript("document.getElementById('afin').selectedIndex = 0");
    $objResponse->addScript("document.getElementById('mfin').selectedIndex = 0");
    $objResponse->addScript("document.getElementById('areacargo').selectedIndex = 0");
    
    return $objResponse;
}

function confirmDelExpLaboral($id){
	global $xoopsDB;
	$objResponse = new xajaxResponse();
	
	$sql = "SELECT * FROM " . $xoopsDB->prefix('jobs_laboralexp') . " WHERE ID = '{$id}'";
    $query = $xoopsDB->query($sql);
    
    $user = $xoopsDB->fetchArray($query);
    
    $sql = "DELETE FROM " . $xoopsDB->prefix('jobs_laboralexp') . " WHERE ID = '{$id}'";
    $xoopsDB->query($sql);
    
    $objResponse->script("xajax_showExpLaboral('{$user['user']}')");
	
	return $objResponse;
}

function addCompetencia($user = 0, $competencia){
    global $xoopsDB;
	$objResponse = new xajaxResponse();
    
    if (0 != $user){
        $sql = "INSERT INTO " . $xoopsDB->prefix('jobs_competencia') . " (user, competencia) VALUES ('{$user}', '{$competencia}')";
        
        $xoopsDB->query($sql);
        
        $objResponse->script("xajax_showCompetencia('{$user}');");
        $objResponse->script("xajax_clearcompetencia()");
    }
    
    return $objResponse;
}

function showCompetencia($user = 0){
    global $xoopsDB;
    $objResponse = new xajaxResponse();
    $html = "<table border=\"1\" width=\"500\">";
    $html .= "<tr><td><b>Competencia</b></td><td><b>Acci&oacute;n</b></td></tr>";
    
    if(0 != $user){
        $sql = "SELECT * FROM " . $xoopsDB->prefix('jobs_competencia') . " WHERE user = '{$user}'";
        $query = $xoopsDB->query($sql);
        while ($data = $xoopsDB->fetchArray($query)) {
            $html .= "<tr id=\"com-{$data['id']}\">";
            $html .= "<td>{$data['competencia']}</td>";
            $html .= "<td><a href=\"javascript:;\" onclick=\"xajax_delCompetencia('{$data['id']}')\">Borrar</a></td>";
            $html .= "</tr>";
        }
		    
    }
    $html .= "</table>";
    
    $objResponse->assign('showCompetencia', 'innerHTML', $html);
    $objResponse->script("xajax_clearcompetencia();");
    return $objResponse;
}

function delCompetencia($id){
    $objResponse = new xajaxResponse();
    
    $objResponse->confirmCommands(0, "Realmente desea eliminar el registro?");
	$objResponse->script("xajax_confirmDelCompetencia('{$id}')");
   
	return $objResponse;
}

function confirmDelCompetencia($id){
    global $xoopsDB;
    $objResponse = new xajaxResponse();
    
    $sql = "SELECT user FROM " . $xoopsDB->prefix('jobs_competencia') . " WHERE id = '{$id}'";
    $query = $xoopsDB->query($sql);
    $data = $xoopsDB->fetchArray($query);
    
    $sql = "DELETE FROM " . $xoopsDB->prefix('jobs_competencia') . " WHERE id = '{$id}'";
    $xoopsDB->query($sql);
    $objResponse->script("xajax_showCompetencia('{$data['user']}');");
    
    return $objResponse;
}

function clearcompetencia(){
    $objResponse = new xajaxResponse();
    
    $objResponse->assign('competencia', 'value', '');
    
    return $objResponse;
}




function addIdioma($user = 0, $idioma, $nivel){
    global $xoopsDB;
	$objResponse = new xajaxResponse();
   // $objResponse->alert("Debe ingresar un idioma");
    //return $objResponse;
    if (0 != $user){
        if(empty($idioma)){
            $objResponse->alert("Debe ingresar un idioma");
            return $objResponse;
        }
        $sql = "INSERT INTO " . $xoopsDB->prefix('jobs_conocimientoidioma') . " (user, idioma, nivel) VALUES ('{$user}', '{$idioma}', '{$nivel}')";
        
        $xoopsDB->query($sql);
        
        $objResponse->script("xajax_showIdioma('{$user}');");
        $objResponse->script("xajax_clearIdioma();");
    }
    
    return $objResponse;
}

function showIdioma($user = 0){
    global $xoopsDB;
    $objResponse = new xajaxResponse();
    $html = "<table border=\"1\" width=\"500\">";
    $html .= "<tr><td><b>Idioma</b></td><td><b>Nivel</b></td><td><b>Acci&oacute;n</b></td></tr>";
    
    if(0 != $user){
        $sql = "SELECT i.*, n.nombre FROM " . $xoopsDB->prefix('jobs_conocimientoidioma') . " i join " . $xoopsDB->prefix('jobs_nivelidioma') . " n ON n.id = i.nivel WHERE user = '{$user}'";
        
        $query = $xoopsDB->query($sql);
        while ($data = $xoopsDB->fetchArray($query)) {
            $html .= "<tr id=\"com-{$data['id']}\">";
            $html .= "<td>{$data['idioma']}</td>";
            $html .= "<td>{$data['nombre']}</td>";
            $html .= "<td><a href=\"javascript:;\" onclick=\"xajax_delIdioma('{$data['id']}')\">Borrar</a></td>";
            $html .= "</tr>";
        }
		    
    }
    $html .= "</table>";
    
    $objResponse->assign('showIdioma', 'innerHTML', $html);
    $objResponse->script("xajax_clearIdioma();");
    return $objResponse;
}

function delIdioma($id){
    $objResponse = new xajaxResponse();
    
    $objResponse->confirmCommands(0, "Realmente desea eliminar el registro?");
	$objResponse->script("xajax_confirmDelIdioma('{$id}')");
    
    return $objResponse;
}

function confirmDelIdioma($id){
    global $xoopsDB;
    $objResponse = new xajaxResponse();
    
   
    $sql = "SELECT user FROM " . $xoopsDB->prefix('jobs_conocimientoidioma') . " WHERE id = '{$id}'";
    $query = $xoopsDB->query($sql);
    $data = $xoopsDB->fetchArray($query);
    
    $sql = "DELETE FROM " . $xoopsDB->prefix('jobs_conocimientoidioma') . " WHERE id = '{$id}'";
    $xoopsDB->query($sql);
    
    $objResponse->script("xajax_showIdioma('{$data['user']}');");
    
    return $objResponse;
}

function clearIdioma(){
    $objResponse = new xajaxResponse();
    
    $objResponse->assign('idioma', 'value', '');
    $objResponse->addScript("document.getElementById('nivelidioma').selectedIndex = 0");
    
    return $objResponse;
}

// Programa
function addConocimiento($user = 0, $conocimiento, $nivel){
    global $xoopsDB;
	$objResponse = new xajaxResponse();
   // $objResponse->alert("Debe ingresar un idioma");
    //return $objResponse;
    if (0 != $user){
        if(empty($conocimiento)){
            $objResponse->alert("Debe ingresar un Conocimiento");
            return $objResponse;
        }
        $sql = "INSERT INTO " . $xoopsDB->prefix('jobs_conocimientoprograma') . " (user, conocimiento, nivel) VALUES ('{$user}', '{$conocimiento}', '{$nivel}')";
        
        $xoopsDB->query($sql);
        
        $objResponse->script("xajax_showConocimiento('{$user}');");
        $objResponse->script("xajax_clearConocimiento();");
    }
    
    return $objResponse;
}

function showConocimiento($user = 0){
    global $xoopsDB;
    $objResponse = new xajaxResponse();
    $html = "<table border=\"1\" width=\"500\">";
    $html .= "<tr><td><b>Conocimiento</b></td><td><b>Nivel</b></td><td><b>Acci&oacute;n</b></td></tr>";
    
    if(0 != $user){
        $sql = "SELECT i.*, n.nombre FROM " . $xoopsDB->prefix('jobs_conocimientoprograma') . " i join " . $xoopsDB->prefix('jobs_nivelconocimiento') . " n ON n.id = i.nivel WHERE user = '{$user}'";
        
        $query = $xoopsDB->query($sql);
        while ($data = $xoopsDB->fetchArray($query)) {
            $html .= "<tr id=\"com-{$data['id']}\">";
            $html .= "<td>{$data['conocimiento']}</td>";
            $html .= "<td>{$data['nombre']}</td>";
            $html .= "<td><a href=\"javascript:;\" onclick=\"xajax_delConocimiento('{$data['id']}')\">Borrar</a></td>";
            $html .= "</tr>";
        }
		    
    }
    $html .= "</table>";
    
    $objResponse->assign('showConocimiento', 'innerHTML', $html);
    $objResponse->script("xajax_clearConocimiento();");
    return $objResponse;
}

function delConocimiento($id){
    $objResponse = new xajaxResponse();
    
    $objResponse->confirmCommands(0, "Realmente desea eliminar el registro?");
	$objResponse->script("xajax_confirmDelConocimiento('{$id}')");
    
    return $objResponse;
}

function confirmDelConocimiento($id){
    global $xoopsDB;
    $objResponse = new xajaxResponse();
    
   
    $sql = "SELECT user FROM " . $xoopsDB->prefix('jobs_conocimientoprograma') . " WHERE id = '{$id}'";
    $query = $xoopsDB->query($sql);
    $data = $xoopsDB->fetchArray($query);
    
    $sql = "DELETE FROM " . $xoopsDB->prefix('jobs_conocimientoprograma') . " WHERE id = '{$id}'";
    $xoopsDB->query($sql);
    
    $objResponse->script("xajax_showConocimiento('{$data['user']}');");
    
    return $objResponse;
}

function clearConocimiento(){
    $objResponse = new xajaxResponse();
    
    $objResponse->assign('conocimiento', 'value', '');
    $objResponse->addScript("document.getElementById('nivelconocimiento').selectedIndex = 0");
    
    return $objResponse;
}


function validatePrice($category = 0, $price){
    global $xoopsDB;
        
    $sql = "SELECT * FROM " . $xoopsDB->prefix('jobs_categories') . " WHERE cid = '{$category}'";
    $query = $xoopsDB->query($sql);
    
    $data = $xoopsDB->fetchArray($query);
    
    if ($price >= $data['affprice']){
        return true;
    }else{
        return false;    
    }
}


?>
